package com.lee.senior;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class WcDo implements WritableComparable<WcDo> {

    private String name;
    private int month;
    private int sale;


    @Override
    public String toString() {
        return   name + "\t" + month + "\t" + sale;
    }


    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(name);
        dataOutput.writeInt(month);
        dataOutput.writeInt(sale);

    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        name = dataInput.readUTF();
        month = dataInput.readInt();
        sale = dataInput.readInt();
    }

    @Override
    public int compareTo(WcDo o) {
        if(o == null) {
            return -1;
        }
        if(o.sale > sale)
        {
            return 1;
        }else if(o.sale < sale){
            return -1;
        }
        return 0;
    }
}
